package controllers;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import models.JSONReqException;
import models.Menu;
import models.Result;
import models.User;

import org.apache.commons.lang.StringUtils;
import org.h2.result.ResultRemote;
import org.tempuri.InJsonData;
import org.tempuri.ReturnResult;
import org.tempuri.WebServiceHelpUtil;

import play.Play;
import play.cache.Cache;
import play.data.Upload;
import play.libs.Files;
import play.mvc.Controller;
import play.mvc.Http.Header;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.JSONLibDataFormatSerializer;

import config.HelpActionConfig;
import config.HelpActionConfig;
import config.AppConfig;
import config.SessionConfig;
import utils.HelpUtils;

public class HelpController extends BaseController{
	
	public static void getHelpDepartmentConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_DEPARTMENT_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpVendorConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_VENDOR_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpSupplierConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_SUPPLIER_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpPersonConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_PERSON_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpVendorModeHelp(){
		User user = getLoginUser();
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_VENDORMODE_HELP, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpVendorTypeHelp(){
		User user = getLoginUser();
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_VENDORTYPE_HELP, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	//供应商分类：无过滤条件
	public static void getHelpSupplierSortHelp(){
		User user = getLoginUser();
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_SUPPLIERSORT_HELP, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(HelpUtils.getErrorMessage(returnResult.getJsonStr()));
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	//资质类型：无过滤条件
	public static void getHelpQualifyKindHelp(){
		User user = getLoginUser();
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_QUALIFYKIND_HELP, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(HelpUtils.getErrorMessage(returnResult.getJsonStr()));
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpAnnounceKindHelp(){
		User user = getLoginUser();
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_ANNOUNCEKIND_HELP , user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(HelpUtils.getErrorMessage(returnResult.getJsonStr()));
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpMultipleMaterialSort(){
		User user = getLoginUser();
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_MULTIPLE_MATERIAL_SORT, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(HelpUtils.getErrorMessage(returnResult.getJsonStr()));
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	
	public static void getHelpWareHouseConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_WAREHOUSE_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpMultipleMaterialDetail(){
		User user = getLoginUser();
		String jsonStr = params.get("data");
		JSONObject reqJson= JSONObject.parseObject(jsonStr);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		JSONArray infoTable = reqJson.getJSONArray("InfoTable");
		if(infoTable.size()!=1){
			JSONObject o = new JSONObject();
			o.put("ConditionString", "");
			jsonList.add(o);
		}else{
			jsonList.add(infoTable.getJSONObject(0));
		}
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		List<JSONObject> materialSortTable = new ArrayList<JSONObject>();
		JSONArray materialSortArray = reqJson.getJSONArray("MaterialSortTable");
		for(int i=0; i<materialSortArray.size();i++){
			materialSortTable.add(materialSortArray.getJSONObject(i));
		}
		dataSet.put("MaterialSortTable", materialSortTable);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_MULTIPLE_MATERIAL_DETAIL, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(HelpUtils.getErrorMessage(returnResult.getJsonStr()));
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	//上传文件
	public static void uploadAttachments(String dirname, File file){
		User user = getLoginUser();
		dirname = user.getDbName();
		JSONObject json = new JSONObject();
		String fileName = file.getName();
		String[] exts = new String[]{"PDF", "TXT", "PNG", "BMP", "GIF", "XLS", "DOCX", "XLSX", "RAR", "ZIP", "7Z", "JPG", "JPEG", "DOC"};
		List<String> list = Arrays.asList(exts);
		String fileExtName = fileName.substring(fileName.lastIndexOf('.')+1, fileName.length());
		if(!list.contains(fileExtName.toUpperCase())){
			json.put("success", false);
			json.put("errorMsg", "未知文件类型");
			renderJSON(json);
			return;
		}
		String uuid = UUID.randomUUID().toString();
		String newFileName = uuid + "." + fileExtName;
		json.put("AttachmentGuid", uuid);
		json.put("FileName", fileName.substring(0, fileName.lastIndexOf('.')));
		String filePath = "public/upload/"+dirname+ "/" + newFileName;
		json.put("FilePath", filePath);
		json.put("Extension", fileExtName);
		json.put("FileWithExtension", fileName);
		json.put("isNew", true);
		SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		json.put("UpdateTime", time.format(new Date()));
		Files.copy(file, Play.getFile(filePath));
		json.put("success", true);
		renderJSON(json);
	}
	
	public static void getHelpMaterialConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_MATERIAL_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	/**
	 * 获取地区参照
	 */
	public static void getHelpRegionConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_REGION_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	/**
	 * 获取行业参照
	 */
	public static void getHelpTradeConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_TRADE_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	/**
	 * 获取结算方式参照
	 */
	public static void getHelpSettleConditionfilter(){
		User user = (User) Cache.get(session.getId());
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_SETTLE_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	/**
	 * 获取运输方式参照
	 */
	public static void getHelpTransferWayConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_TRANSFERWAY_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	/**
	 * 获取付款条件参照
	 */
	public static void getHelpPaymentTermConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_PAYMENTTERM_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	/**
	 * 获取开票类型参照
	 */
	public static void getHelpBillingTypeConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_BILLINGTYPE_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	/**
	 * 获取供应商分类参照
	 */
	public static void getHelpSupplierSortConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_SUPPLIERSORT_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	/**
	 * 获取供应商分类参照
	 */
	public static void getHelpMaterialSortConditionfilter(){
		User user = getLoginUser();
		String key = params.get("key");
		JSONObject queryJson = new JSONObject();
		queryJson.put("ConditionString", key);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		jsonList.add(queryJson);
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_MATERIALSORT_CONDITIONFILTER, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(returnResult.getJsonStr());
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpMultipleVendorSort(){
		User user = getLoginUser();
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_MULTIPLE_VENDOR_SORT, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(HelpUtils.getErrorMessage(returnResult.getJsonStr()));
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
	
	public static void getHelpMultipleVendorDetail(){
		User user = getLoginUser();
		String jsonStr = params.get("data");
		JSONObject reqJson= JSONObject.parseObject(jsonStr);
		List<JSONObject> jsonList = new ArrayList<JSONObject>();
		JSONArray infoTable = reqJson.getJSONArray("InfoTable");
		if(infoTable.size()!=1){
			JSONObject o = new JSONObject();
			o.put("ConditionString", "");
			jsonList.add(o);
		}else{
			jsonList.add(infoTable.getJSONObject(0));
		}
		Map<String, List<JSONObject>> dataSet= new HashMap<String, List<JSONObject>>();
		dataSet.put("InfoTable", jsonList);
		List<JSONObject> vendorSortTable = new ArrayList<JSONObject>();
		JSONArray vendorSortArray = reqJson.getJSONArray("VendorSortTable");
		for(int i=0; i<vendorSortArray.size();i++){
			vendorSortTable.add(vendorSortArray.getJSONObject(i));
		}
		dataSet.put("VendorSortTable", vendorSortTable);
		String jsonData = InJsonData.getRequsetJsonData("0", HelpActionConfig.HELP_MULTIPLE_VENDOR_DETAIL, user.getUsername(), AppConfig.CURRENT_PLAT, user.getDbName(), request.remoteAddress, "", dataSet);
		Result result  = new Result();
		try {
			ReturnResult returnResult = WebServiceHelpUtil.execute(jsonData);
			if(returnResult.isSuccess()){
				result.setCode(AppConfig.SUCCESS);
				JSONObject json = JSONObject.parseObject(returnResult.getJsonStr());
				JSONArray jsonArray = json.getJSONArray("ReturnTable");
				result.setData(jsonArray);
			}else{
				result.setCode(AppConfig.ERROR);
				result.setMessage(HelpUtils.getErrorMessage(returnResult.getJsonStr()));
			}
		} catch (Exception e) {
			throw new JSONReqException(e.getMessage());
		}
		renderJSON(result);
	}
}
